<?php 
header("content-type:text/html;charset=utf8");
/**
 * 
 */
class Test extends IController
{
	public function act()
	{
		$id = $_GET['id'];
		$id = base64_decode($id);
		$model = new IModel('email_user');
		$model->setData(array('status'=>1));
		$res = $model->update("id=$id");
		if ($res) {
			echo "<script>alert('激活成功');location='http://www.iwebshop.com/test/login/id/$id'</script>";
		}
		 
	}
	public function join_do()
	{
		$u_name = IReq::get('u_name');
		$u_pwd = IReq::get('u_pwd');
		$u_email = IReq::get('u_email');
		$arr = array('u_name'=>$u_name,'u_pwd'=>$u_pwd,'u_email'=>$u_email,'status'=>0);
		$model = new IModel('email_user');
		$model->setData($arr);
		$res = $model->add();
		if ($res) {
			$title = "恭喜您,注册成功";
			$url = "http://www.iwebshop.com/test/act/id/".base64_encode($res);
			$content = "欢迎加入我们,请赶快去激活吧".$url;
			$email = new SendMail();
			$email->send($u_email,$title,$content);
		}

	}
	public function login()
	{
		$id = isset($_GET['id'])?$_GET['id']:1;
		$this->id=$id;
		$this->redirect('login');
	}
	public function login_do(){
        $u_name = IReq::get('u_name');
		$u_pwd = IReq::get('u_pwd');
		$model = new IModel('email_user');
		$res = $model->query("u_name ='$u_name' and u_pwd = '$u_pwd'");
		if ($res) {
            if ($res['status'] == 1) {
            	echo "<script>alert('登录成功');location='http://www.iwebshop.com/test/join'</script>";
            }
            else
            {
            	echo "<script>alert('您还没有激活');location='http://www.iwebshop.com/test/login'</script>";
            }
			
		}
		else{
			echo "<script>alert('用户名或密码错误');location='http://www.iwebshop.com/test/login'</script>";
		}
	}
	public function file()
	{
		$this->redirect("file");
	}
	public function bigfile()
	{
		$file = $_FILES['sliceFile'];
		//print_r($file);
		$tmp_name = $file['tmp_name'];
		$sliceNo = $_POST['sliceNo'];//切片编号
        $blob_count = $_POST['blob_count'];
        $filename = $_POST['filename'];
        //移动临时文件
        $this->movesliceFile($tmp_name,$filename,$sliceNo);
        if ($blob_count == $sliceNo) {
        	$this->mergesliceFile($tmp_name,$filename,$sliceNo);//合并切片
        	$this->deletesliceFile($filename,$sliceNo);//删除切片

        }
		
	}
	public function movesliceFile($tmp_name,$filename,$sliceNo)
	{
        $destination = "upload/video/".$filename."_".$sliceNo;
        move_uploaded_file($tmp_name,$destination);
	}
	public function mergesliceFile($tmp_name,$filename,$sliceNo)
	{
		$data = "";
		for ($i=1; $i <=$sliceNo ; $i++) { 
			$path = "upload/video/".$filename."_".$i;
			$data.=file_get_contents($path);
		}
		$new_path = "upload/video/".$filename;
        file_put_contents($new_path, $data);
	}
	public function deletesliceFile($filename,$sliceNo){
		for ($i=1; $i <=$sliceNo ; $i++) { 
			$path = "upload/video/".$filename."_".$i;
			unlink($path);
		}
	}

}
















 ?>